package com.kotlinvben.controller

import com.kotlinvben.bean.Result
import com.kotlinvben.service.UserService
import com.kotlinvben.vo.UserLoginVo
import jakarta.validation.Valid
import org.springframework.web.bind.annotation.*

/**
 * @author wxluo2
 * @date 2025/5/29 10:08
 */
@RestController
@RequestMapping("/auth")
class AuthController(
    private val userService: UserService
) {

    @PostMapping("/login")
    fun login(@Valid @RequestBody loginVo: UserLoginVo): Result<UserLoginVo> {
        return Result.success(userService.login(loginVo))
    }

    @PostMapping("/refresh")
    fun refresh(@RequestHeader("Authorization") token: String): Result<String> {
        return Result.success(userService.refreshToken(token))
    }

    @PostMapping("/logout")
    fun logout(@RequestHeader("Authorization") token: String): Result<Unit> {
        userService.logout(token)
        return Result.success()
    }

    @GetMapping("/codes")
    fun codes(): Result<List<String>> {
        return Result.success(listOf("AC_100100", "AC_100110", "AC_100120", "AC_100010"))
    }

}